﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;

public partial class ePioneer_ep_real_page : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strFolder = this.realname.Value;
        string strContent = elm1.Value.ToString();


        strContent += "";

        StringBuilder strhtml = new StringBuilder();
        strhtml.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
        strhtml.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");//+ strContent + "</html>");
        strhtml.Append("<head>");
        strhtml.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />");
        strhtml.Append("<title></title>");
        strhtml.Append("<link href=\"css/page.css\" rel=\"stylesheet\" type=\"text/css\" />");
       
      
        strhtml.Append("</head>");
        strhtml.Append("<body>");
        strhtml.Append(strContent);
        strhtml.Append("</body>");
        strhtml.Append("</html>");

        string strFolderPath = "E://公司项目//[CMS]//CMS//CMS//ePioneer//data/" + strFolder ;
        string File = strFolderPath + "/" + strFolder +".html";

        if (System.IO.File.Exists(strFolderPath))
        {
            System.IO.File.Delete(strFolderPath);
        }

        string from = "E://公司项目//[CMS]//CMS//CMS//ePioneer//data/" + "/template";
        CopyFolder(from, strFolderPath);


        FileInfo fino = new FileInfo(File);
        using (FileStream ft = fino.OpenWrite())
        {
            StreamWriter sw = new StreamWriter(ft, Encoding.Default);
            sw.Write(strhtml);
            sw.Flush();
            sw.Close();
        }


    }


    private static void CopyFolder(string from, string to)
    {
        if (!Directory.Exists(to))
            Directory.CreateDirectory(to);
        // 子文件夹
        foreach (string sub in Directory.GetDirectories(from))
            CopyFolder(sub + "\\", to + "\\" + Path.GetFileName(sub) + "\\");
        // 文件
        foreach (string file in Directory.GetFiles(from))
            File.Copy(file, to + "\\" + Path.GetFileName(file), true);
    }
}